/**
 * @author   Ivan Andonov
 * @email:   ivan.andonov[at]gmail[dot]com
 * 
 * @require  sjs, sjs.Delegate, sjs.Utils, jquery
 * @use      sjs.Debug
 * @optional 
 **/

(function() {
	sjs.create('sjs.Form.Option', {
		
		// CONSTRUCTOR
		initiallize : function(props, option) {
			//$log(this+' props='+props+' option='+option);
			// PUBLIC VARS
			this.option = option || new Option();
			for (var prop in props) {
				if (typeof(props[prop]) != 'function') {
					switch (prop) {
						case 'text':
						case 'value':
						case 'disabled':
						case 'selected':
						case 'defaultSelected':
						case 'className':
						case 'id':
							this.option[prop] = props[prop];
							break;
						case 'class':
							this.option['className'] = props[prop];
							break;
						case 'option':
							break;
						default:
							//$log('WARNING: unexpected prop of option: '+prop+'='+props[prop]);
					}
				}
			}
			
			// PUBLIC METHODS
			this.getProp = function(prop) {
				//$log(this+'.getProp prop='+prop);
				return this.option[prop];
			};
			
			this.setProp = function(prop, value) {
				//$log(this+'.setProp prop='+prop+' value='+value);
				this.option[prop] = value;
			};
			
			this.toObject = function() {
				//$log(this+'.toObject');
				var attrName, attrValue;
				var obj = { text:this.option.text||'' };
				var count = this.option.attributes.length;
				for (var k = 0; k < count; k++) {
					attrName = this.option.attributes[k].name.toLowerCase();
					attrValue = this.option.attributes[k].value;
					switch (attrName) {
						case 'class':
							attrName = 'className';
							break;
						case 'value':
							var value_arr = attrValue.split(' ');
							obj.type = value_arr[1];
							attrValue = value_arr[0];
							break;
					}
					obj[attrName] = attrValue;
				}
				return obj;
			};
		}
		
	});
	
})();